﻿using DemoWebapi01.Entities;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Microsoft.EntityFrameworkCore;

namespace DemoWebapi01.EntityTypeConfiguration
{
    public class CategoryETConfig : IEntityTypeConfiguration<Category>
    {
        public void Configure(EntityTypeBuilder<Category> builder)
        {
            // 主键
            builder.HasKey(c => c.CategoryID);

            // 属性配置
            builder.Property(c => c.Name)
                .IsRequired()
                .HasMaxLength(200);

            builder.Property(c => c.Icon)
                .HasMaxLength(50);

            builder.Property(c => c.Description);

            builder.Property(c => c.DisplayOrder)
                .HasDefaultValue(0);
        }
    }
}
